#include "renderer.h"
#include "rd_surface.h"

#include <stdio.h>
#include <string.h>

model_t * rd_load_model(const char * modelname)
{
	if (rd.model_count >= MAX_MODELS) {
		com_error("too much models loaded!!!");
		return NULL;
	}

	model_t * m = &rd.models[rd.model_count];
	strncpy(m->name, modelname, MAX_OSPATH);

	char texfile[MAX_OSPATH+30];

	sprintf(texfile, "../data/model/%s/walk2.png", modelname);
	m->sprite[0] = rd_load_surface(texfile);
	sprintf(texfile, "../data/model/%s/run.png", modelname);
	m->sprite[1] = rd_load_surface(texfile);

	if (m->sprite[0] && m->sprite[1] == NULL) {
		com_error("fail to load model!!!");
		return NULL;
	}

	m->w = 40;
	m->h = 40;
	m->step[0] = 25;
	m->frames[0] = 8;
	m->num = rd.model_count;

	rd.model_count++;

	return m;
}

rect_t * rd_model_clip(model_t * m, int direction, int frame)
{
	static rect_t clip;

	clip.x = m->w * frame;
	clip.y = m->h * direction;
	clip.w = m->w;
	clip.h = m->h;

	return &clip;
}

void rd_free_models(void)
{
	;
}


